package com.user.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.user.entity.user;
import com.user.service.userservice;

@WebServlet("/Doupdateuser")
public class Doupdateuser extends HttpServlet{
	private static final long serialVersionUID = 1L;
    
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Doupdateuser() {
        super();
        // TODO Auto-generated constructor stub
    }

	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		response.setContentType("textml;charset=utf-8");

		String id = request.getParameter("id");
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String phone = request.getParameter("phone");
		System.out.println(id+phone+password+phone);
		user pu=new user();
		pu.setId(Integer.parseInt(id));
		pu.setUsername(username);
		pu.setPassword(password);
		pu.setPhone(Integer.parseInt(phone));
		userservice p=new userservice();
		boolean i = p.Updateuser(pu);
		if(i){
			request.setAttribute("msg", "修改成功！");
			System.out.println("修改成功！");
			request.getRequestDispatcher("Doselectuser").forward(request, response);
		}else{
			request.setAttribute("msg", "修改失败！");
			System.out.println("修改失败");
			request.getRequestDispatcher("userxx.jsp").forward(request, response);
		}
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
